package com.weishi.project.speedometer.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * 移动平均线指标
 * zoulj 2021-08-04
 */
public class MaFilter {

    public static List getMA(List<Double> entries, int n) {
        List result = new ArrayList<>();
        for (int i = 0, len = entries.size(); i < len; i++) {
            if (i < n - 1) {
                continue;
            }
            float sum = 0;
            for (int j = 0; j < n; j++) {
                sum += entries.get(i - j);
            }
            result.add(sum / n);
        }
        return result;
    }

}
